// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Mint from 'mint-ui'
import VueResource from 'vue-resource'
import VideoPlayer from 'vue-video-player'

import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'

Vue.use(VueResource)
Vue.use(Mint);
Vue.use(VideoPlayer)


Vue.config.productionTip = false

Vue.http.options.crossOrigin = false;
Vue.http.options.emulateHTTP = false;

Vue.http.interceptors.push((request, next) => {
  request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
  let TOKEN = sessionStorage.getItem('X-CSRF-TOKEN');
  if (TOKEN) {
    request.headers.set('X-CSRF-TOKEN', TOKEN);
  }
  next((response) => {
    if (response.body.status === 'UNAUTHORIZED') {
      // sessionStorage.removeItem('TOKEN')
      location.href = '/passwordLogin'
    }
    return response;
  });
});

router.beforeEach((to, from, next) => {
  window.scrollTo(0, 0);
  next()
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})